import { request } from '@/service'

interface ResultType {
  result: {
    resultCode: string
    resultMessage: string
  }
  data: object
}

/** 适配接口返回结果 */
function adapter(obj: ResultType) {
  if (obj.result?.resultCode === '000000') {
    return obj.data
  }
  throw new Error('错误')
}

/** 监测报警记录 start */
//分页查询报警规则配置信息
export const queryPageBjgzpz = (params?: any) =>
  request.get('/bjgzpz/query/page/bjgzpz', { params }).then((res: any) => adapter(res))

//新增或修改报警规则配置表
export const insertOrUpdate = (data?: any) =>
  request.post('/bjgzpz/insertOrUpdate', data).then((res: any) => adapter(res))

/** 告警统计分析 start */
//根据时间范围查询告警处置情况分析(告警处置情况分析)
export const queryBjjlCzqkTjxx = (params?: any) =>
  request.get('/bjjl/queryBjjlCzqkTjxx', { params }).then((res: any) => adapter(res))

//根据时间范围查询告警等级占比分析(告警占比情况分析-等级)
export const queryBjjlDjzbTjxx = (params?: any) =>
  request.get('/bjjl/queryBjjlDjzbTjxx', { params }).then((res: any) => adapter(res))

//根据时间范围查询告警类型占比分析(告警占比情况分析-类型)
export const queryBjjlLxzbTjxx = (params?: any) =>
  request.get('/bjjl/queryBjjlLxzbTjxx', { params }).then((res: any) => adapter(res))

//查询报警类型每日统计信息(告警趋势分析)
export const queryBjlxMrTjxx = (params?: any) =>
  request.get('/bjjl/queryBjlxMrTjxx', { params }).then((res: any) => adapter(res))

//根据时间范围查询告警时段统计信息
export const queryBjjlSdTjxx = (params?: any) =>
  request.get('/bjjl/queryBjjlSdTjxx', { params }).then((res: any) => adapter(res))
/** 告警统计分析 end */
//分页查询报警记录信息
export const queryPageBjjl = (params?: any) =>
  request.get('/bjjl/query/page/bjjl', { params }).then((res: any) => adapter(res))

//查询监测点位图表数据
export const queryJcdwTbInfo = (params?: any) =>
  request.get('/jcdw/queryJcdwTbInfo', { params }).then((res: any) => adapter(res))
